﻿using Dapper;
using Entity;
using IRealize;
using Microsoft.Data.SqlClient;
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Realize
{
    public class SGD:ISGD
    {
        

        public async Task<List<Salary_Grant_Details>> Server(string sgid,string sqlserver)
        {
            Task<List<Salary_Grant_Details>> task = Task<List<Salary_Grant_Details>>.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(sqlserver))
                {

                    string sql = $"select * from salary_grant_details where salary_grant_id = '{sgid}'";
                    return con.Query<Salary_Grant_Details>(sql).ToList();
                }
            });
            return await task;
        }
        public async Task<List<Salary_Grant_Details>> Server2(string h_id,string sqlserver)
        {
            Task<List<Salary_Grant_Details>> task = Task<List<Salary_Grant_Details>>.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(sqlserver))
                {

                    string sql = $"select * from salary_grant_details where human_id = '{h_id}'";
                    return con.Query<Salary_Grant_Details>(sql).ToList();
                }
            });
            return await task;
        }
        public async Task<int> Insert(string sg_id, string h_id, string h_name, decimal b_sum, decimal s_sum, decimal d_sum, decimal ss_sum, decimal sp_sum, string sqlserver)
        {
            using (SqlConnection sqlConnection = new SqlConnection(sqlserver))
            {
                string sql = $@"insert into salary_grant_details(salary_grant_id,human_id,human_name,bouns_sum,sale_sum,deduct_sum,salary_standard_sum,salary_paid_sum)
                 values('{sg_id}','{h_id}','{h_name}',{b_sum},{s_sum},{d_sum},{ss_sum},{sp_sum})";
                return await sqlConnection.ExecuteAsync(sql);
            }
        }

        public async Task<int> Update(string h_id, decimal b_sum, decimal s_sum, decimal d_sum, decimal sp_sum, string sqlserver)
        {
            using (SqlConnection sqlConnection = new SqlConnection(sqlserver))
            {
                string sql = $@"update salary_grant_details set bouns_sum = {b_sum},sale_sum={s_sum},deduct_sum={d_sum} , salary_paid_sum={sp_sum}
                  where human_id = '{h_id}'";
                return await sqlConnection.ExecuteAsync(sql);
            }
        }
    }
}
